from typing import List
from core.step_model import StepModel, RunModel
from core.common import formatter_log, single_replace_data
from core.check import loop_assert_by_check_list


def is_run_step(run_data: List[RunModel], params_class, case_logs_obj, result=True) -> bool:
    """
    判断是否执行该测试步骤，True执行步骤，False不执行该步骤
    """
    if not run_data:
        return result

    result = loop_assert_by_check_list(run_data, params_class, case_logs_obj, is_check=False)
    case_logs_obj.logs.append(formatter_log('info', "【IF 表达式的结果为： {}】".format(result)))
    return result


def get_loop_number(one_step_data: StepModel, params_class, case_logs_obj) -> int:
    """
    获取循环执行的次数，返回一个数字
    """
    if not one_step_data.loop:
        return False

    exp = one_step_data.loop[0].exp
    _type = one_step_data.loop[0].type
    exp = exp if _type == 'Int' else single_replace_data(params_class, case_logs_obj, exp)
    case_logs_obj.logs.append(formatter_log('info', "【循环执行次数为： {}】".format(exp)))
    return exp
